package com.heima.wemedia.controller;


import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.NewsDto;
import com.heima.model.wemedia.dtos.WmNewsDownOrUpDto;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.model.wemedia.entity.WmNews;
import com.heima.wemedia.service.WmNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 自媒体文章表(WmNews)表控制层
 *
 * @author makejava
 * @since 2023-06-14 09:36:39
 */
@Api(tags = "文章接口")
@RestController
@RequestMapping("api/v1/news")
public class WmNewsController {
    /**
     * 服务对象
     */
    @Resource
    private WmNewsService wmNewsService;

    @ApiOperation("发布文章接口")
    @PostMapping("/submit")
    public ResponseResult submitNews(@RequestBody WmNewsDto wmNewsDto){

        return wmNewsService.submitNews(wmNewsDto);

    }

    @ApiOperation("文章列表查询")
    @PostMapping("/list")
    public ResponseResult listNews(@RequestBody WmNewsPageReqDto wmNewsPageReqDto){

        return wmNewsService.pageList(wmNewsPageReqDto);
    }

    @ApiOperation("编辑文章")
    @GetMapping("/one/{id}")
    public ResponseResult editNews(@PathVariable Long id){

        return wmNewsService.editNews(id);
    }

    @ApiOperation("删除文章")
    @GetMapping("/del_news/{id}")
    public ResponseResult deleteNews(@PathVariable Long id){

        return wmNewsService.deleteNews(id);
    }

    @ApiOperation("上下架文章")
    @PostMapping("/down_or_up")
    public ResponseResult upOrDownNews(@RequestBody WmNewsDownOrUpDto dto){
        return wmNewsService.upOrDowmNews(dto);
    }


    /**
     * 查询文章列表
     * @param dto
     * @return
     */
    @PostMapping("/list_vo")
    public ResponseResult list(@RequestBody NewsDto dto){

        return wmNewsService.apNewsList(dto);

    }

    @GetMapping("/one_vo/{id}")
    public ResponseResult getById(@PathVariable Integer id){

        return wmNewsService.findById(id);
    }


    @PostMapping("/auth_fail")
    public ResponseResult fail(@RequestBody NewsDto dto){
        return wmNewsService.audit(dto);
    }

    @PostMapping()
    public ResponseResult pass(@RequestBody NewsDto dto){
        return wmNewsService.audit(dto);
    }



}

